/**
 * 
 */
package com.chinasofti.project.components;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author caojinping
 * 2018年9月28日
 */
public class NotLoginInterceptor implements HandlerInterceptor {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.web.servlet.HandlerInterceptor#afterCompletion(javax.
	 * servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
	 * java.lang.Object, java.lang.Exception)
	 */
	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.web.servlet.HandlerInterceptor#postHandle(javax.
	 * servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
	 * java.lang.Object, org.springframework.web.servlet.ModelAndView)
	 */
	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.web.servlet.HandlerInterceptor#preHandle(javax.
	 * servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
	 * java.lang.Object)
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {

		HttpSession session = request.getSession();
		String requestURI = request.getRequestURI();

		Object isLogin = session.getAttribute("user");
		if (isLogin == null) {
			if (requestURI.equalsIgnoreCase("/breeze/toBreezeShopcart")) {
				session.setAttribute("OP", "toBreezeShopcart");
				request.setAttribute("msg", "您还未登录");
				request.getRequestDispatcher("toLogin").forward(request, response);
				return false;
			}
			if (requestURI.equalsIgnoreCase("/breeze/addShopcart")) {
				request.setAttribute("msg", "您还未登录");
				request.getRequestDispatcher("toLogin").forward(request, response);
				return false;
			}
			if (requestURI.equalsIgnoreCase("/breeze/toFavorite")) {
				session.setAttribute("OP", "toFavorite");
				request.setAttribute("msg", "您还未登录");
				request.getRequestDispatcher("toLogin").forward(request, response);
				return false;
			}
			if (requestURI.equalsIgnoreCase("/breeze/lineItem")) {
				session.setAttribute("OP", "lineItem");
				request.setAttribute("msg", "您还未登录");
				request.getRequestDispatcher("toLogin").forward(request, response);
				return false;
			}
			if (requestURI.equalsIgnoreCase("/breeze/toBreezeWelcome")) {
				session.setAttribute("OP", "toBreezeWelcome");
				request.setAttribute("msg", "您还未登录");
				request.getRequestDispatcher("toLogin").forward(request, response);
				return false;
			}
			if (requestURI.equalsIgnoreCase("/breeze/toBreezeIntegral")) {
				session.setAttribute("OP", "toBreezeIntegral");
				request.setAttribute("msg", "您还未登录");
				request.getRequestDispatcher("toLogin").forward(request, response);
				return false;
			}
		}
		return true;
	}

}

